package com.glink.manage.service.Impl;

import com.glink.manage.domain.PersonSyncRecordBean;
import com.glink.manage.mapper.PersonSyncRecordMapper;
import com.glink.manage.service.PersonSyncRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author  qiushaoshan
 * @since 2025-03-04
 */
@Service
public class PersonSyncRecordServiceImpl extends ServiceImpl<PersonSyncRecordMapper, PersonSyncRecordBean> implements PersonSyncRecordService {

    /**
     * 根据设备号删除同步记录
     *
     * @param devSno 设备号
     */
    @Override
    @Transactional(value = "transactionManager", propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void removeByDevSno(String devSno) {
        this.lambdaUpdate().eq(PersonSyncRecordBean::getDevSno, devSno).remove();
        
    }

    /**
     * 根据设备号删除同步记录
     *
     * @param devSno   设备号
     * @param personId 人员
     */
    @Override
    @Transactional(value = "transactionManager", propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void removeByDevSnoAndId(String devSno, Integer personId) {
        this.lambdaUpdate().eq(PersonSyncRecordBean::getDevSno, devSno)
                .eq(PersonSyncRecordBean::getId, personId).remove();
    }

    /**
     * 统计已经同步数量
     *
     * @param devSno 设备号
     * @return 总数
     */
    @Override
    public Integer countByDevSno(String devSno) {
        return this.lambdaQuery().eq(PersonSyncRecordBean::getDevSno, devSno).count();
    }
}
